﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "overallsituation.h"
#include "thread.h"
#include "socket.h"

#include <QMainWindow>
//qtservice库要的
#include <QCoreApplication>
#include "qtservice.h"
//USB库要的
//USB
#include <QtCore>
#include <libudev.h>

#include<QString>
#include<QDebug>
#include <QDir>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class WindowService : public QtService<QCoreApplication>
{
public:
    WindowService(int argc, char **argv);
    ~WindowService()override;


protected:
    //启动
    void start()override;
    //停止
    void stop()override;
    //暂停
    void pause()override{}
    //重新启动
    void resume()override{}


private:

};



class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    void handleDeviceEvent(int socket);

private:
    Ui::MainWindow *ui;
    struct udev* udev;
    struct udev_monitor* monitor;
    QSocketNotifier* notifier;
    Socket *socket;
    ThreadPool *C6Thread;
    ThreadPool *T6Thread;
    ThreadPool *R1Thread;
    ThreadPool *A3Thread;
    ThreadPool *C7Thread;
    //ThreadPool *C7Thread1;
    ThreadPool *UpThread;
    ThreadPool *PUpThread;


    QTimer* timer;//心跳请求定时器
    QTimer* Threadtimer;//线程队列定时器
      QTimer*  sockettimer;
    QTimer* ThreadUI;//心跳请求定时器
          QTimer*  Usbtimer;

    std::list<DeviceInforMation> C6ThreadTask;//线程任务队列
    //     std::list<DeviceInforMation> T6ThreadTask;//线程任务队列
    //     std::list<DeviceInforMation> R1ThreadTask;//线程任务队列
    std::list<DeviceInforMation> A3ThreadTask;//线程任务队列
    std::list<DeviceInforMation> C7ThreadTask;//线程任务队列
    std::list<UploadInfo> UpThreadTask;//线程任务队列
    std::list<UploadInfo> PUpThreadTask;//线程任务队列
        bool Config_Heavylod();
private slots:
    //void RegisterDevice();
    //bool nativeEvent(const QByteArray &eventType, void *message, long *result);
    void SendMessageNotifica(int ParentID, int SubID, int state);//发送消息
    void SendUiMessageNotifica1(int ParentID, int SubID, int SerialportNum, QString Text, QString TextInfo, int Textprompt, int Display);
    void SendIMMessageNotifica(int ParentID, int SubID, InterfaceMappingInfo Info);
    void SendDIMMessageNotifica(int ParentID, int SubID, DeviceInforMation Info);
    void SendPoliceMode(int ParentID, int SubID);
    //void handlePrint(QString text);
    //void ThreadRestart(int ThreadID);
    void ThreadJoin(int serialportnum,QString vid ,QString pid,QString serialnumber);
    void ThreadUpload(int serialportnum,QString userID,QString pwd);
    void ThreadPriorUpload(int serialportnum,QString userID,QString pwd);
    void ThreadTimer(int serialportnum,bool IsStart);
        void ThreadBandingUpload(int serialportnum);

};
#endif // MAINWINDOW_H
